# -*- coding: utf-8 -*-
import pytest
from selenium import webdriver
from a3mall_yeu_lianxi.Page.Page_login import PageLogin
from time import sleep
from selenium.webdriver.common.by import By
from a3mall_yeu_lianxi.Tools.Tools import Tools
import logging


class TestCase:
    def setup_method(self):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()

        logging.info('准备测试环境')

    def teardown_method(self):
        sleep(5)
        self.driver.quit()
        logging.info('清理测试环境')

    @pytest.mark.parametrize('data', Tools().Yaml('../Data/log.yaml'))
    def test_01_log(self, data):
        logging.info('开始测试登录')
        po = PageLogin(self.driver)
        po.open_url('http://10.59.9.12:7001/')
        po.login()
        dy1 = self.driver.find_element(By.CLASS_NAME, 'reg-new').text
        assert dy1 == '会员登录'
        po.username(data['username'])
        po.password(data['password'])
        sleep(15)
        po.loginbtn()
        if data["username"] == 18462371409:
            print('qwertyui')
            try:
                dy2 = self.driver.find_element(By.XPATH, '/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[1]').text
                assert data["dy"] in dy2
            except Exception as e:
                po.save()
                logging.info('报错信息：', e)

        else:
            try:
                dy3 = self.driver.find_element(By.CLASS_NAME, 'reg-new').text
                assert dy3 == data["dy"]
            except Exception as e:
                po.save()
                logging.info('报错信息：', e)
        logging.info('测试完成')


if __name__ == '__main__':
    pytest.main()
